package com.itheima.controller;

import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.service.CheckGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {

    @Autowired
    private CheckGroupService checkGroupService;

    /**
     * 添加检查组
     * @param checkitemIds
     * @param checkGroup
     * @return
     */
    @PostMapping("/add")
    public Result add(String[] checkitemIds, @RequestBody CheckGroup checkGroup) {
        checkGroupService.add(checkitemIds, checkGroup);
        return new Result(true, "新增检查组成功");
    }

    /**
     * 分页条件查询
     *
     * @param queryPageBean
     * @return
     */
    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = checkGroupService.findPage(queryPageBean);
        return pageResult;
    }

    /**
     * 根据id删除检查组
     *
     * @param id
     * @return
     */
    @GetMapping("/deleteById")
    public Result delete(String id) {
        checkGroupService.delete(id);
        return new Result(true, "删除检查组成功");
    }

    /**
     * 根据id查询检查组
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public Result findById(String id) {
        CheckGroup checkGroup = checkGroupService.findById(id);
        return new Result(true, "查询检查组成功", checkGroup);
    }

    /**
     * 编辑检查组
     * @param checkitemIds
     * @param checkGroup
     * @return
     */
    @PostMapping("/edit")
    public Result edit(String[] checkitemIds, @RequestBody CheckGroup checkGroup) {
        checkGroupService.edit(checkitemIds, checkGroup);
        return new Result(true, "编辑检查组成功");
    }

    /**
     * 查询所有检查组
     * @return
     */
    @GetMapping("/findAll")
    public Result findAll() {
        List<CheckGroup> list = checkGroupService.selectAll();
        return new Result(true, "查询检查组成功", list);
    }

    /**
     * 根据套餐id查询关联的检查组id
     * @param setmealId
     * @return
     */
    @GetMapping("/findCheckGroupIdsBySetmealId")
    public Result findCheckGroupIdBySetmealId(String setmealId) {
        List<Integer> checkGroupIds = checkGroupService.findCheckGroupId(setmealId);
        return new Result(true, "查询检查组成功", checkGroupIds);
    }

}
